package ch10_IO流与文件.打印流;

import java.io.*;

/**
 * @author 挚爱之夕
 * @date 2021/8/27 - 08 - 27 - 15:42
 * @Description: ch10.打印流
 * @Version: 1.0
 */
public class PrintStreamDemo {
    public static void main(String[] args) {
        //包含byte、char、int、long、float、double、String等类型的对象数组
        Object[] values = {(byte)-8,'A','我',Integer.MAX_VALUE,022,0x1A,987654321L,3.14159,-1.7F,2.1D,"Java语音",System.lineSeparator()};
        File file = new File("E:/Test.txt");    //写到的文件

        try(FileOutputStream out = new FileOutputStream(file);
            PrintStream log = new PrintStream(out)){
            for (Object v: values
                 ) {
                log.print(v+"|");   //写出values的每个元素
            }
            byte[] bytes = {65,66,67,13,10};    //字节数组（A、B、C及Windows换行符）
            log.write(bytes,1,bytes.length-1);//从B开始写出
            char[] chars = {'\t','J','a','v','a','语','言'};
            log.print(chars);   //写出字符数组
        }catch(FileNotFoundException e){
            System.out.println("创建文件时发生错误！");
        }catch(IOException e){
            System.out.println("读写时发生错误！");
        }
    }
}
